//
//  HHWelcomeViewController.m
//  HHBroker
//
//  Created by Herui on 9/1/15.
//  Copyright © 2015 harry. All rights reserved.
//

#import "HHWelcomeViewController.h"
#import "HHLoginViewController.h"
#import "HHSignInViewController.h"
#import "UIViewAdditions.h"
#import "HHContactUsViewController.h"

@interface HHWelcomeViewController ()

@property (nonatomic, strong) UIButton *loginButton;
@property (nonatomic, strong) UIButton *signInButton;
@property (nonatomic, strong) UIButton *contactUsButton;

@end

@implementation HHWelcomeViewController

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - Life Cycle

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    self.view.backgroundColor = [UIColor greenColor];
//    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
//    button.frame = CGRectMake(100, 200, 200, 40);
//    button.backgroundColor = [UIColor yellowColor];
//    [button setTitle:@"go to next" forState:UIControlStateNormal];
//    [button addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
//    [self.view addSubview:button];
    
    UIImageView *backi = [[UIImageView alloc] initWithFrame:self.view.frame];
    backi.image = [UIImage imageNamed:@"welcome_background"];
    [self.view addSubview:backi];
    [self.view addSubview:self.signInButton];
    [self.view addSubview:self.loginButton];
    [self.view addSubview:self.contactUsButton];
    
}
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    if (self.nextToGo == JYADLogin) {
        self.nextToGo = JYADUnset;
        HHLoginViewController *login = [[HHLoginViewController alloc] init];
        [self.navigationController pushViewController:login animated:YES];
    }
    if (self.nextToGo == JYADRegister) {
        self.nextToGo = JYADUnset;
        HHSignInViewController *signin = [[HHSignInViewController alloc] init];
        [self.navigationController pushViewController:signin animated:YES];
    }
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.hidden = NO;
}

- (void)buttonClick
{
    HHLoginViewController *hhl = [[HHLoginViewController alloc] init];
    //UINavigationController *navi = [[UINavigationController alloc]initWithRootViewController:hhl];
    // 导航只有一个，一系列用一个
        [self.navigationController pushViewController:hhl animated:YES];
}

#pragma mark  - Event
- (void)loginButtonClicked:(UIButton *)button
{
    HHLoginViewController *hhl = [[HHLoginViewController alloc] init];
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:nil];
    self.navigationItem.backBarButtonItem = item;
    [self.navigationController pushViewController:hhl animated:YES];
}

- (void)signButtonClicked:(UIButton *)button
{
    HHSignInViewController *hhs = [[HHSignInViewController alloc] init];
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:nil];
    self.navigationItem.backBarButtonItem = item;
    [self.navigationController pushViewController:hhs animated:YES];
}

- (void)contactUsButtonClicked:(UIButton *)button
{
    HHContactUsViewController *hhc = [[HHContactUsViewController alloc] init];
    //UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:nil];
    //self.navigationItem.backBarButtonItem = item;
    [self.navigationController pushViewController:hhc animated:YES];

}
#pragma mark - Setter && Getter

- (UIButton *)loginButton
{
    if (_loginButton == nil) {
        _loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _loginButton.frame = CGRectMake(self.signInButton.left, self.signInButton.top-12-44, self.signInButton.width, self.signInButton.height);
        [_loginButton setTitle:@"登陆" forState:UIControlStateNormal];
        _loginButton.titleLabel.font = [UIFont systemFontOfSize:17];
        [_loginButton setBackgroundImage:[UIImage imageNamed:@"button_denglu_normal"] forState:UIControlStateNormal];
        [_loginButton setBackgroundImage:[UIImage imageNamed:@"button_denglu_press"] forState:UIControlStateHighlighted];
        [_loginButton addTarget:self action:@selector(loginButtonClicked:)forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _loginButton;
}

- (UIButton *)signInButton
{
    if (_signInButton == nil) {
        _signInButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _signInButton.frame = CGRectMake(45, self.contactUsButton.top-30-40, self.view.width-90, 44);
        [_signInButton setTitle:@"注册" forState:UIControlStateNormal];
        _signInButton.titleLabel.font = [UIFont systemFontOfSize:17];
        [_signInButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
        [_signInButton setBackgroundImage:[UIImage imageNamed:@"button_sign_normal"] forState:UIControlStateNormal];
        [_signInButton setBackgroundImage:[UIImage imageNamed:@"button_signin_press"] forState:UIControlStateHighlighted];
        [_signInButton addTarget:self action:@selector(signButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
        
    }

    return _signInButton;
}


- (UIButton *)contactUsButton
{
    if (_contactUsButton == nil) {
        _contactUsButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _contactUsButton.frame = CGRectMake(0, self.view.bottom-30-15, 82, 15);
        _contactUsButton.centerX = self.view.centerX;
        [_contactUsButton setTitle:@"联系我们" forState:UIControlStateNormal];
        _contactUsButton.titleLabel.font = [UIFont systemFontOfSize:17.0f];
        [_contactUsButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
        [_contactUsButton setBackgroundImage:[UIImage imageNamed:@"button_img_contract"] forState:UIControlStateNormal];
        _contactUsButton.imageEdgeInsets = UIEdgeInsetsMake(0, 63, 0, 0);//有偏差
        _contactUsButton.titleEdgeInsets = UIEdgeInsetsMake(0, -19*2, 0, 0);
        [_contactUsButton addTarget:self action:@selector(contactUsButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
        
        
        
    }
    
    return _contactUsButton;
}


@end
